	<?php 
	require_once __DIR__."/../Models/series.php";
	use Symfony\Component\HttpFoundation\Request;

	$series_model = new Models\Series($app);
	$series = $app['controllers_factory'];

	

	$series->get('/', function() use ($app, $series_model){
		$res = $series_model->getAll();
		return $app['twig']->render('tab.html', array('data'=>json_encode($res)));
	});

	$series->post('/', function(Request $request) use ($app, $series_model){

		echo "post";

		$data = array(
			"series_type"=>'1',
			"series_name"=>$request->get("series_name"),
			"series_season"=>$request->get("series_season"),
			"series_count"=>$request->get("series_count"),
			"series_link"=>$request->get("series_link"),
			"series_date"=>$request->get("series_date"),
		);
		//echo json_encode( $data );

		echo "befor insert";

		$res = $series_model->insert($data);
		//return json_encode($res);
		return $app->redirect( $app['homepage_route'] );
	});


	$series->get('/{id}' , function($id) use($app, $series_model){
		$res = $series_model->getOne((int) $id);
		return json_encode($res);
	});

	$series->post('/{id}' , function($id, Request $request) use($app, $series_model){
		$method = $request->get('method');
		if( $method == "inc" ){
			$res = $series_model->inc((int) $id);	
			return json_encode($res);
		}else if($method == "edit"){
			$data = $request->get('data');
			$data = array(
					'series_type' => $data['series_type'],
					'series_name' => $data['series_name'],
					'series_season' => $data['series_season'],
					'series_count' => $data['series_count'],
					'series_link' => $data['series_link']
				);
			$res = $series_model->update($id, $data);	
			return json_encode($data);
		}
	});
	
	$series->delete('/{id}' , function($id) use($app, $series_model){
		$res = $series_model->delete((int) $id);
		$res = "delete $id";
		return json_encode($res);

	});

	return $series;

?>